import { AudioType, ListenEventType, TouchEventType } from "../../util/defineConfig";
import View from "../../util/View";
import GameView from "../gameView";
import nakama from "../nakama";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends View {

  private gameView:GameView = null

  private view:any = {}
  private peopleSelectBtn:cc.Node[] = []

  init(gameView:GameView){
      this.gameView = gameView
  }
  
  onLoad(){
    this.view = this.load_all_object(this.node,'')
    this.peopleSelectBtn.push(this.view['bg_select_players/but_p2'])
    this.peopleSelectBtn.push(this.view['bg_select_players/but_p3'])
    this.peopleSelectBtn.push(this.view['bg_select_players/but_p4'])

    this.peopleSelectBtn.forEach((item,index)=>{
        item.on(TouchEventType.touchStart,()=>{this.selectPeopleByIndex(index)},this)
    })
 
  }

  private async selectPeopleByIndex(index){
    this.emit(ListenEventType.PLAY_EFFECT,AudioType.press_button)
    let match = await nakama.findMatch()
    if(match)
      this.gameView.loadGameScene(index)
  }
}
